const app = getApp()
var that;
Page({
  data: {
    pullUrl: "",
    width: '100%',
    height: '320',
    fullScreenFlag: false 
  },
  onResize(res) {
    console.log(res);
    if(res.deviceOrientation=="portrait"){
      this.setData.width = '100%'; // 新的显示区域宽度
      this.setData.height = '320'; // 新的显示区域高度
    } else {
      this.setData.width = res.size.windowWidth; // 新的显示区域宽度
      this.setData.height = res.size.windowHeight; // 新的显示区域高度
    }

  },
  start: function () {},
  recordTap: function () {
    wx.navigateTo({
      url: '../mp4/mp4'
    })
  },
  BackPage() {
    wx.navigateTo({
      url: '../index/index'
    })
  },
  loadVideo: function () {
    wx.request({
      url: app.globalData.serverUrl + '/alivePush',
      method: 'GET',
      dataType: 'json',
      date: {},
      success: function (res) {
        console.log(res.data);
        if (res.data.hasOwnProperty('error_code')) {
          wx.showToast({
            title: '流媒体出错了！', // 标题
            icon: 'none', // 图标类型，默认success
            duration: 3000 // 提示窗停留时间，默认1500ms
          })
        
        } else {
          that.setData({
            pullUrl: res.data.response.paras.addr
          })
          wx.showToast({
            title: '视频正在加载中', // 标题
            icon: 'none', // 图标类型，默认success
            duration: 4000 // 提示窗停留时间，默认1500ms
          })   
        }
      }
    })

  },
  fullScreen: function () {
    console.log("fullScreen")
    this.ctx = wx.createLivePlayerContext('myplayer');
    if(this.data.fullScreenFlag){
      console.log(this.data.fullScreenFlag)
      this.ctx.exitFullScreen();
      that.setData({
        fullScreenFlag: false
      })
    } else {
      console.log(this.data.fullScreenFlag)
      that.setData({
        fullScreenFlag: true
      })
      this.ctx.requestFullScreen({
        success: res => {
          console.log('play success')
        },
        fail: res => {
          console.log('play fail')
        },direction: 90
      })
    }

  },
  onLoad: function () {
    that = this;
  }
})